class BaseSerilaizer(object):
    def __init__(self, instance=None, data=None):
        """
            初始化方法
        :param instance: 数据对象
        :param data: 验证数据
        """
        self.instance = instance
        self.valid_data = data

    def is_valid(self):
        """
            验证方法
        :return:
        """
        self.validated_data = self.validate(self.valid_data)

        return self.validated_data

    def save(self):
        """
            保存或更新方法
        :return:
        """
        if self.instance is not None:
            self.instance = self.update(self.instance, self.validated_data)
        else:
            self.instance = self.create(self.validated_data)

        return self.instance

    @property
    def data(self):
        """
            序列化返回方法
        :return:
        """
        if self.instance is None:
            return self.validated_data
        return self.instance

    def validate(self, attrs):
        """
            子类实现的验证方法
        :param attrs:
        :return:
        """
        pass

    def create(self, validated_data):
        """
            子类实现的保存方法
        :param validated_data:
        :return:
        """
        pass

    def update(self, instance, validated_data):
        """
            子类实现的更新方法
        :param instance:
        :param validated_data:
        :return:
        """
        pass

class A():
    field='aaa'
    class Meta:
        model='python'


print(A().Meta.model)
print(A().field)